#pragma once
#include <Windows.h>
#include "D3D9.h"
#include "IGraphic.h"
#include "GraphicDef.h"
#include "CRenderBatchManager.h"

class ITexture;

class CGraphic : public IGraphic
{
public:
	CGraphic( HWND hWnd );
	~CGraphic(void);

	virtual VBOOL		Create( const SGraphicInfo& GraphicInfo );
	virtual VBOOL		Release();

	virtual VBOOL		RenderBegin();
	virtual VBOOL		RenderEnd();

	virtual VBOOL		Render( const SRenderOperator* pRenderOperator );

	virtual VBOOL		SetCameraParam( const CVector3& vecCameraPos, const CVector3& vecCameraTarget, float32 fFarPlane, float32 fNearPlane, float32 fFov, float32 fRatio );
	virtual void		SetCleanColor( uint32 uColor );

	virtual ITexture*	CreateTexture( VCHAR* szTextutreName );
	virtual void		ReleaseTexture( ITexture* pTexture );
	virtual VBOOL		SetTexture( int32 nStage, const ITexture* pTexture );

	virtual VBOOL		Render( ERenderBatchMapType eRenderBatchMapType, ERenderBatchType eRenderBatchType, IRenderUnit* pRenderUnit );

	virtual VBOOL		Render2DSprite( const void* pVertextBuffer, const void* pIndexBuffer, int32 nVertexNum, int32 nVertexStride, VBOOL bAlphaBlend, uint8 uAlpha );
	virtual VBOOL		Render2DSpriteList( const void* pVertextBuffer, const void* pIndexBuffer, int32 nVertexNum, int32 nVertexStride, int32 nRectCount, VBOOL bAlphaBlend, uint8 uAlpha );

	virtual VBOOL		Run();

	//////////////////////////////////////////////////////////////////////////
	IDirect3DDevice9*	GetD3DDevice() { return m_pD3DDevice; }

private:

	//////////////////////////////////////////////////////////////////////////
	void				Set2DSpriteRenderState( VBOOL bAlphaBlend, uint8 uAlpha );
	void				SetDefaultRenderState();

private:

	HWND					m_hWnd;

	/// D3D
	IDirect3D9*				m_pD3D;
	IDirect3DDevice9*		m_pD3DDevice;

	D3DPRESENT_PARAMETERS	m_PresenParam;
	VBOOL					m_bPresent;

	uint32					m_uCleanColor;

};
